package edu.ccut.saturn.basevalidate.businessvalidate;

import edu.ccut.saturn.component.DefaultSaturnValidate;
import edu.ccut.saturn.component.ValidateResult;

public class RegexValidate extends DefaultSaturnValidate {
	/**
	 * 正则表达式校验,不需要输入开始结束标记
	 */

	@Override
	protected void doValidate(Object value, Object[] args, ValidateResult result) {
		if (args == null || args.length == 0) {
			sendError(_ARGERROR_, value, result);
		} else {
			String regex = (String) args[0];
			String origin = value + ""; 
			if (!origin.matches(regex)) {
				sendError(_ERROR_, value, result);
			}
		}
	}
}
